﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using AdminApp.Web.Services;

namespace AdminApp
{
    public class SpeakerConverter : IValueConverter
    {
        public DigitalSignageDomainContext SpeakerData
        {
            get { return this._context; }
            set { this._context = value; }
        }

        public static readonly DependencyProperty SessionDataProperty =
            DependencyProperty.Register(
                "SpeakerData",
                typeof(SessionConverter),
                typeof(DigitalSignageDomainContext), 
                new PropertyMetadata(null, OnSpeakerDataChanged));

        private static void OnSpeakerDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            
        }

        public SpeakerConverter()
        {
        }

        private DigitalSignageDomainContext _context;

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return string.Empty;
            }
            int sessionId = (int)value;

            if (_context != null)
            {
                var result = _context.Speakers.Where(s => s.Id == sessionId).First();
                return result.Firstname + " " + result.Lastname;
            }
            else
            {
                return string.Empty;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
